package 数组的操作;

import java.util.Scanner;

public class Df_01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int [][] d = new int[n+1][n+1];
        // 输入d
        for (int i = 1; i < n+1; i++) {
            for (int j = 1; j <= i; j++) {
                d[i][j] = scanner.nextInt();
            }
        }
        // 找最优路径
        for (int i = n; i >= 1; i--) {
            for (int j = 1; j <= i; j++) {
                if (i==n){
                    d[i][j] = d[i][j];
                }else {
                    d[i][j] = Math.max(d[i+1][j],d[i+1][j+1])+d[i][j];
                }
            }
        }
        System.out.println(d[1][1]);
    }
}
